from classfile.constant_info import ConstantInfo


class ConstantMemberRefInfo(ConstantInfo):
    def __init__(self, cp):
        self.cp = cp
        self.classIndex = 0
        self.nameAndTypeIndex = 0

    def readInfo(self, clsReader):
        self.classIndex = int.from_bytes(clsReader.readU16(), "big")
        self.nameAndTypeIndex = int.from_bytes(clsReader.readU16(), "big")

    def getClassName(self):
        return self.cp.getClassName(self.classIndex)

    def getNameAndType(self):
        return self.cp.getNameAndType(self.nameAndTypeIndex)


class ConstantFieldRefInfo(ConstantMemberRefInfo):
    def __init__(self, constMemberRefInfo):
        super().__init__(None)
        self.constMemberRefInfo = constMemberRefInfo


class ConstantMethodRefInfo(ConstantMemberRefInfo):
    def __init__(self, constMemberRefInfo):
        super().__init__(None)
        self.constMemberRefInfo = constMemberRefInfo


class ConstantInterfaceMethodInfo(ConstantMemberRefInfo):
    def __init__(self, constMemberRefInfo):
        super().__init__(None)
        self.constMemberRefInfo = constMemberRefInfo

